package com.yvtian.pu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yvtian.pu.pojo.PuOrderEntity;
import com.yvtian.pu.pojo.PuReturnOrderEntity;
import com.yvtian.pu.dao.PuReturnOrderMapper;
import com.yvtian.pu.service.PuReturnOrderService;
import com.yvtian.utils.StringHelper;
import org.springframework.stereotype.Service;

/**
 * 采购退货单(pu_return_order)表服务实现类
 *
 * @author long
 * @since 2024-06-24 10:26:29
 */
@Service("puReturnOrderService")
public class PuReturnOrderServiceImpl extends ServiceImpl<PuReturnOrderMapper, PuReturnOrderEntity> implements PuReturnOrderService {

    @Override
    public IPage<PuReturnOrderEntity> findByPage(Page<PuReturnOrderEntity> page, PuReturnOrderEntity puReturnOrderEntity) {
        LambdaQueryWrapper<PuReturnOrderEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PuReturnOrderEntity::getIsDel, 0);
        getQueryWrapper(puReturnOrderEntity, queryWrapper);
        return this.page(page, queryWrapper);
    }

    private void getQueryWrapper(PuReturnOrderEntity puReturnOrderEntity, LambdaQueryWrapper<PuReturnOrderEntity> queryWrapper) {
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getCode())) {
            queryWrapper.like(PuReturnOrderEntity::getCode, puReturnOrderEntity.getCode());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getReturnDateStr())) {
            String returnDateStr = puReturnOrderEntity.getReturnDateStr().trim();
            String[] split = returnDateStr.split("~");
            queryWrapper.between(PuReturnOrderEntity::getReturnDate, split[0], split[1]);
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getReturnUsername())) {
            queryWrapper.like(PuReturnOrderEntity::getReturnUsername, puReturnOrderEntity.getReturnUsername());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getReturnAccount())) {
            queryWrapper.like(PuReturnOrderEntity::getReturnAccount, puReturnOrderEntity.getReturnAccount());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getStockCode())) {
            queryWrapper.like(PuReturnOrderEntity::getStockCode, puReturnOrderEntity.getStockCode());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getStockName())) {
            queryWrapper.like(PuReturnOrderEntity::getStockName, puReturnOrderEntity.getStockName());
        }
        if (ObjectUtils.isNotEmpty(puReturnOrderEntity.getReturnStatus())) {
            queryWrapper.eq(PuReturnOrderEntity::getReturnStatus, puReturnOrderEntity.getReturnStatus());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getPuOrderCode())) {
            queryWrapper.like(PuReturnOrderEntity::getPuOrderCode, puReturnOrderEntity.getPuOrderCode());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getSupplierCode())) {
            queryWrapper.like(PuReturnOrderEntity::getSupplierCode, puReturnOrderEntity.getSupplierCode());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getSupplierName())) {
            queryWrapper.like(PuReturnOrderEntity::getSupplierName, puReturnOrderEntity.getSupplierName());
        }
        if (ObjectUtils.isNotEmpty(puReturnOrderEntity.getAmount())) {
            queryWrapper.eq(PuReturnOrderEntity::getAmount, puReturnOrderEntity.getAmount());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getProjectCode())) {
            queryWrapper.like(PuReturnOrderEntity::getProjectCode, puReturnOrderEntity.getProjectCode());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getProjectName())) {
            queryWrapper.like(PuReturnOrderEntity::getProjectName, puReturnOrderEntity.getProjectName());
        }
        if (ObjectUtils.isNotEmpty(puReturnOrderEntity.getStatus())) {
            queryWrapper.eq(PuReturnOrderEntity::getStatus, puReturnOrderEntity.getStatus());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getCreateName())) {
            queryWrapper.like(PuReturnOrderEntity::getCreateName, puReturnOrderEntity.getCreateName());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getUpdateName())) {
            queryWrapper.like(PuReturnOrderEntity::getUpdateName, puReturnOrderEntity.getUpdateName());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getCreateUser())) {
            queryWrapper.like(PuReturnOrderEntity::getCreateUser, puReturnOrderEntity.getCreateUser());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getRemarks())) {
            queryWrapper.like(PuReturnOrderEntity::getRemarks, puReturnOrderEntity.getRemarks());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getCheckName())) {
            queryWrapper.like(PuReturnOrderEntity::getCheckName, puReturnOrderEntity.getCheckName());
        }
        if (StringHelper.isNotEmpty(puReturnOrderEntity.getCheckUser())) {
            queryWrapper.like(PuReturnOrderEntity::getCheckUser, puReturnOrderEntity.getCheckUser());
        }
    }
}

